;(function(fav){
  $(function(){
    $('.js_fav_create').live('click', function(){
      var favObj = $(this);
      var res_name = favObj.data('resname');
      var res_id   = favObj.data('resid');
      $.post(
          "fav/save/index",
          { 'res_name':res_name, 'res_id':res_id },
          function(data){
              if(data.info == 'ok') {
                alert('收藏成功');
                favObj.removeClass('js_fav_create');
                favObj.addClass('js_fav_delete');
                favObj.html('取消收藏');
              } else {
                alert(data.msg);
              }
          },'json')
    });
    
    $('.js_fav_delete').live('click', function(){
      var favObj = $(this);
      var res_name = favObj.data('resname');
      var res_id   = favObj.data('resid');
      $.post(
          "fav/delete/index",
          { 'res_name':res_name, 'res_id':res_id },
          function(data){
              if(data.info == 'ok') {
                alert('取消收藏成功');
                favObj.removeClass('js_fav_delete');
                favObj.addClass('js_fav_create');
                favObj.html('收藏');
              } else {
                alert(data.msg);
              }
          },'json')
    });
  });
})(window);